﻿using Microsoft.AspNetCore.Http;
using NetCoreCMS.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NetCoreCMS.Web.Areas.WebApi.Models
{
    public class CheckCode
    {
        #region 校检网站验证码OK===============================
        public static string verify_code(string strcode,HttpContext ctx)
        {
            if (string.IsNullOrEmpty(strcode))
            {
                return "{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}";
            }
            if (ctx.Session.GetString(CMSKeys.SESSION_CODE) == null)
            {
                return "{\"status\":0, \"msg\":\"对不起，验证码超时或已过期！\"}";
            }
            if (strcode.ToLower() != (ctx.Session.GetString(CMSKeys.SESSION_CODE)).ToLower())
            {
                return "{\"status\":0, \"msg\":\"您输入的验证码与系统的不一致！\"}";
            }
            ctx.Session.Remove(CMSKeys.SESSION_CODE);
            return "success";
        }
        #endregion

        #region 校检手机验证码OK===============================
        public static string verify_sms_code(string strcode, HttpContext ctx)
        {
            if (string.IsNullOrEmpty(strcode))
            {
                return "{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}";
            }
            if (ctx.Session.GetString(CMSKeys.SESSION_SMS_CODE) == null)
            {
                return "{\"status\":0, \"msg\":\"对不起，验证码超时或已过期！\"}";
            }
            if (strcode.ToLower() != (ctx.Session.GetString(CMSKeys.SESSION_SMS_CODE)).ToLower())
            {
                return "{\"status\":0, \"msg\":\"您输入的验证码与系统的不一致！\"}";
            }
            ctx.Session.Remove(CMSKeys.SESSION_SMS_CODE);
            return "success";
        }
        #endregion
    }
}
